package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.AgedmallAgentComboMapper;
import org.linlinjava.litemall.db.dao.app.AppAgentMapper;
import org.linlinjava.litemall.db.domain.AgedmallAgentCombo;
import org.linlinjava.litemall.db.domain.AgedmallAgentComboExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AgedmallAgentComboService {
    @Resource
    private AgedmallAgentComboMapper agedmallAgentComboMapper;
    @Resource
    private AppAgentMapper appAgentMapper;

    public void add(AgedmallAgentCombo agedmallAgentCombo) {
        agedmallAgentCombo.setAddTime(LocalDateTime.now());
        agedmallAgentCombo.setUpdateTime(LocalDateTime.now());
        agedmallAgentComboMapper.insertSelective(agedmallAgentCombo);
    }

    public AgedmallAgentCombo getById(Integer id) {
        return agedmallAgentComboMapper.selectByPrimaryKey(id);
    }

    public void update(AgedmallAgentCombo agedmallAgentCombo) {
        agedmallAgentCombo.setUpdateTime(LocalDateTime.now());
        agedmallAgentComboMapper.updateByPrimaryKeySelective(agedmallAgentCombo);
    }

    public void deleteBatch(List<Integer> ids) {
        AgedmallAgentComboExample example = new AgedmallAgentComboExample();
        example.or().andIdIn(ids);
        AgedmallAgentCombo combo = new AgedmallAgentCombo();
        combo.setDeleted(true);
        agedmallAgentComboMapper.updateByExampleSelective(combo, example);
    }

    public List<AgedmallAgentCombo> comboList(Integer agentId, String keyword, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return appAgentMapper.comboList(agentId, keyword);
    }

    public List<AgedmallAgentCombo> shareComboList(List<Integer> ids) {
        AgedmallAgentComboExample example = new AgedmallAgentComboExample();
        example.or().andDeletedEqualTo(false).andIdIn(ids);
        return agedmallAgentComboMapper.selectByExample(example);
    }
}
